﻿using System;
using System.Collections.Generic;
using System.Web.UI;
using Ext.Net;
using Kwan.Cache;

namespace ZP.Web.Admin
{
    public class UIPage : System.Web.UI.Page
    {
        //public static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        //创建，读取，更新，删除，审核
        //00000 表示没有任何权限，共5位
        protected string currenturl = string.Empty;
        //protected Dictionary<string, object> modules;
        protected bool[] permit;

        protected override void OnPreInit(EventArgs e)
        {
            base.OnPreInit(e);
            //DateTime dt = DateTime.Now;
            CacheManage cache = CacheManage.Instance;
            //判断角色是否能访问该文件
            currenturl = Kwan.Helper.Strings.Format.CutString(Request.RawUrl, "/Ext/", "/Default.aspx")[0].ToLower();
            string[] arr = currenturl.Split('/');
            currenturl = arr[arr.Length - 1];
            //从缓存中获取
            Dictionary<string, object> modules = cache.Get(Page.User.Identity.Name) as Dictionary<string, object>;
            if (modules != null)
            {
                //List<TModule> child = modules.FindAll(delegate(TModule tt) { return tt.Name == currenturl; });
                //if (child.Count == 0)
                if (!modules.ContainsKey(currenturl))
                    Response.Redirect("~/Ext/404.htm", true);
                permit = modules[currenturl] as bool[];
            }
            else
            {
                Response.Redirect("~/ExtLogin.aspx", true);
            }
            //ExtHelper.ErrorMsg("msg", (DateTime.Now - dt).TotalSeconds.ToString(), "");
        }


    }
}